<template>
  <div>
    <el-dialog
        style="z-index: auto;"
        title="个人信息"
        :close-on-click-modal="false"
        width="30%"
        :visible.sync="visible">
      <el-form :model="dataForm" ref="dataForm"
               label-width="80px" :hide-required-asterisk="true" v-if="ChangeInfoVisible==false">
        <el-form-item label="id" prop="id">
          <el-input readonly v-model="dataForm.id"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input readonly v-model="dataForm.name"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="number">
          <el-input readonly v-model="dataForm.number"></el-input>
        </el-form-item>
        <el-form-item label="支付积分" prop="point">
          <el-input readonly v-model="dataForm.point"></el-input>
        </el-form-item>
        <el-form-item label="等级" prop="level">
          <el-input readonly v-model="dataForm.level"></el-input>
        </el-form-item>
        <el-form-item label="住址" prop="address">
          <el-input readonly v-model="dataForm.address"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="margin-left: -60px" @click="visible = false">确定</el-button>
          <el-button type="primary" @click="ChangeInfoVisible=true">修改个人信息</el-button>
        </el-form-item>
      </el-form>

      <el-form v-if="ChangeInfoVisible == true" :model="dataForm" ref="dataForm"
               label-width="80px" :hide-required-asterisk="true">
        <el-form-item label="id" prop="id">
          <el-input readonly v-model="dataForm.id"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="number">
          <el-input v-model="dataForm.number"></el-input>
        </el-form-item>
        <el-form-item label="住址" prop="address">
          <el-input v-model="dataForm.address"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
          <el-button @click="ChangeInfoVisible = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import request from "@/utils/request";

export default {
  data() {
    return {
      visible: false,
      ChangeInfoVisible: false,
      dataForm: {
        id: '',
        name: '',
        number: '',
        point: 0,
        level: '',
        address: 0,

      },

    }
  },
  methods: {

    handleChange(value) {
      console.log(value);
    },
    init() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        request.get(`/user/client/init`, {}).then((response) => {
          if (response.data && response.data.code === 200) {
            console.log(response.data)
            this.dataForm.id = response.data.info.id
            this.dataForm.name = response.data.info.name
            this.dataForm.number = response.data.info.number
            this.dataForm.point = response.data.info.point
            this.dataForm.level = response.data.info.level
            this.dataForm.address = response.data.info.address
          }
        })

      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {

          request.post('/user/client/modify', {
            'id': this.dataForm.id,
            'name': this.dataForm.name,
            'number': this.dataForm.number,
            'address': this.dataForm.address
          }).then(response => {
            if (response.data && response.data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.ChangeInfoVisible = false

                }
              })
            } else {
              this.$message.error(response.data.msg)
            }
          })
        }
      })
    }
  }
}
</script>
  